/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: dell
 * Date: 2023-12-11
 * Time: 18:30
 */
import java.lang.reflect.Array;
import java.util.Arrays;

public class SeqList {
    private int[] arr;
    private int usedSize;
    private static final int Defaultsize=4;
    public SeqList() {
        this.arr = new  int[Defaultsize];
    }
    public boolean isfull(){
        return usedSize==arr.length;
    }
    public void add(int tmp){
        if(isfull()){
            arr= Arrays.copyOf(arr,2*arr.length);
        }
        this.arr[usedSize]=tmp;
        usedSize++;
    }
    public void display(){
        for (int i=0;i < this.usedSize;i++){
            System.out.print(arr[i]+" ");
        }
        System.out.println();
    }
    public boolean contains(int tmp){
        for (int i=0;i<this.usedSize;i++){
            if (arr[i]==tmp){
                return true;
            }
        }
        return false;
    }
    public int indexof(int pos){
        for (int i=0;i<this.usedSize;i++){
            if (arr[i]==pos){
                return i;
            }
        }
        return -1;
    }
    public boolean isEmpy(){
        if (usedSize==0){
            return true;
        }
        return false;
    }
    public int get(int pos){
        if (pos > usedSize||pos < 0){
            return -1;
        }else {
            return arr[pos];
        }
    }
    public void remove(int pos){
        if (pos>usedSize||pos<0){
            throw new posoutboundsExeption("get 位值不合法");
        }else {
            for (int i=pos;i<usedSize;i++){
                arr[i]=arr[i+1];
            }
            usedSize--;
        }
    }
    public void add(int tmp,int pos){
        if(isfull()){
            arr= Arrays.copyOf(arr,2*arr.length);
        }
        if (tmp>usedSize||tmp<0){
            throw new posoutboundsExeption("get 位值不合法");
        }else{
            for(int i=usedSize;i>tmp;i--){
                arr[i]=arr[i-1];
            }
            arr[tmp]=pos;
            usedSize++;
        }
    }
    public void set(int tmp,int pos){
        if (tmp>usedSize||tmp<0){
            throw new posoutboundsExeption("get 位值不合法");
        }
        arr[tmp]=pos;

    }
    public void removeto(int pos){
        if (!isEmpy()){
            throw new posoutboundsExeption("错误");
        }
        for (int i=0;i<this.usedSize;i++){
            if (arr[i]==pos){
                remove(i);
            }
        }
    }
    public  int size(){
        return usedSize;
    }
    public void clear() {
        for (int i = 0; i < this.usedSize; i++) {
            //  arr[i]=null;
        }
        usedSize=0;
    }

}